<%--
  Created by IntelliJ IDEA.
  User: pc
  Date: 2023/6/17
  Time: 11:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>派发生产增加页面</title>

    <!-- 引入 layui.css -->
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>

<%--增加--%>
    <div class="layui-container">
        <form class="layui-form" action="#" id="addfm">
            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-block">
                    <input type="text" name="productionPlanId"  lay-verify="required" placeholder="编号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单id</label>
                <div class="layui-input-block">
                    <input type="text"  name="orderId" lay-verify="required" placeholder="订单id" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排班时间</label>
                <div class="layui-input-block">
                    <input type="text"  name="scheduleTime" lay-verify="required" placeholder="排班时间" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">计划生产量</label>
                <div class="layui-input-block">
                    <input type="text"  name="schedeleCount" lay-verify="required" placeholder="计划生产量" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-block">
                    <input type="text"  name="departmentId" lay-verify="required" placeholder="部门" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">尺码</label>
                <div class="layui-input-block">
                    <input type="text"  name="sizeId" lay-verify="required" placeholder="尺码" autocomplete="off" class="layui-input">
                </div>
            </div>
        </form>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit onclick="addProductionplan()" lay-filter="submitForm">确认增加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
</form>
</div>




<script>
    layui.use('form', function(){
        var form = layui.form;

        // 监听表单提交
        form.on('submit(submitForm)', function(data){
            // 提交表单的逻辑处理
            console.log(data.field);
            return false; // 阻止表单跳转
        });
    });
</script>

<script type="text/javascript">

    function addProductionplan() {
        var  ProductionPlan= fmobjToObj($("#addfm"));
        $.ajax({
            url     :  '${pageContext.request.contextPath}/productionplans/addproductionPlan',    // 要提交的URL路径
            type    :  "post",      // 发送请求的方式
            contentType:"application/json",
            data    : JSON.stringify(ProductionPlan) ,      // 要发送到服务器的数据
            dataType :  "json",     // 预期接收到的数据格式
            "beforeSend": function() {     //请求之前的方法
                console.log("我要发送请求了");
            },
            "success"  :  function(result) {  // 请求成功后要执行的代码
                alert(JSON.stringify(result))
                if (result.code===20000){
                    alert("添加成功");
                    window.location.href="toPlanList";
                }else {
                    alert("添加失败");
                }
            },
            "error"       :  function() {     // 请求失败后要执行的代码
                alert("网络正忙，请稍等！！！")
            }
        })
    }

    function  fmobjToObj(fmobj){
        var o = {};
        var a = fmobj.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }

</script>
</body>

</html>
